//
//  Action_collectionViewCellCycle.m
//  EggSteward
//
//  Created by 王道林 on 16/9/3.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "Action_collectionViewCellCycle.h"
#import "DLMacro.h"
#import "BaseLabel.h"
#import "BaseButton.h"
#import "Aciotn_WDLCycleView.h"
#import "DLWNetworkingParser.h"

@interface Action_collectionViewCellCycle ()<WDLCycleDelegateO>
@property (nonatomic, strong) BaseButton *buttonSignIn;
@property (nonatomic, strong) BaseButton *buttonTurnTable;
@property (nonatomic, strong) BaseButton *buttonAction;
@property (nonatomic, strong) BaseButton *buttonTask;
@property (nonatomic, strong) WDLCycleViewO *cycleview;
// block
@property (nonatomic, copy) void(^blockSingIn)();
@property (nonatomic, copy) void(^blockTurnTable)();
@property (nonatomic, copy) void(^blockAction)();
@property (nonatomic, copy) void(^blockTack)();
@end

@implementation Action_collectionViewCellCycle

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

#pragma mark - 创建tableView的头视图
- (void)createSubView
{
    // 轮播图
    _cycleview = [[WDLCycleViewO alloc] initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, 190)];
    _cycleview.delegate = self;
    [self.contentView addSubview:_cycleview];
    // 四个button
    _buttonSignIn = [BaseButton buttonWithType:UIButtonTypeCustom];
    [_buttonSignIn setImage:[UIImage imageNamed:@"qiandao"] forState:UIControlStateNormal];
    _buttonSignIn.frame = CGRectMake(15, 200, (self.contentView.frame.size.width - 120) / 4, 65);
    [_buttonSignIn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_buttonSignIn];
    
    _buttonTurnTable = [BaseButton buttonWithType:UIButtonTypeCustom];
    [_buttonTurnTable setImage:[UIImage imageNamed:@"zhuanpan"] forState:UIControlStateNormal];
    _buttonTurnTable.frame = CGRectMake(self.contentView.frame.size.width / 4 + 15, 200, (self.contentView.frame.size.width - 120) / 4, 65);
    [_buttonTurnTable addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_buttonTurnTable];
    
    _buttonAction = [BaseButton buttonWithType:UIButtonTypeCustom];
    [_buttonAction setImage:[UIImage imageNamed:@"huodong1"] forState:UIControlStateNormal];
    _buttonAction.frame = CGRectMake(self.contentView.frame.size.width / 2 + 15, 200, (self.contentView.frame.size.width - 120) / 4, 65);
    [_buttonAction addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_buttonAction];
    
    _buttonTask = [BaseButton buttonWithType:UIButtonTypeCustom];
    [_buttonTask setImage:[UIImage imageNamed:@"renwu"] forState:UIControlStateNormal];
    _buttonTask.frame = CGRectMake(self.contentView.frame.size.width / 4 * 3 + 15, 200, (self.contentView.frame.size.width - 120) / 4, 65);
    [_buttonTask addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_buttonTask];
    NSArray *arr = @[@"每日签到", @"大转盘", @"现场活动", @"每日任务"];
    for (NSInteger i = 0; i < 4; i++)
    {
        BaseLabel *lable = [[BaseLabel alloc] initWithFrame:CGRectMake(self.contentView.frame.size.width / 4 * i , 270, self.contentView.frame.size.width / 4, 25)];
        lable.textAlignment = 1;
        lable.text = arr[i];
        [self.contentView addSubview:lable];
    }
    
}

// set赋值
- (void)setArrData:(NSMutableArray *)arrData
{
    _arrData = arrData;
 
    _cycleview.arrayImage = _arrData;
}

// button的点击方法

- (void)buttonAction:(BaseButton *)button
{
    if (button == _buttonSignIn)
    {
        self.blockSingIn();
    }
    else if (button == _buttonTurnTable)
    {
        self.blockTurnTable();
    }
    else if (button == _buttonAction)
    {
        self.blockAction();
    }
    else if (button == _buttonTask)
    {
        self.blockTack();
    }
}

- (void)buttonActionBlockSingIn:(void (^)())blcokSingIn blockTurn:(void (^)())blockTurn blockAction:(void (^)())blockAction blockTack:(void (^)())blockTack
{
    _blockSingIn = blcokSingIn;
    _blockTurnTable = blockTurn;
    _blockAction = blockAction;
    _blockTack = blockTack;
}


// 轮播图的代理方法的实现
- (void)backActionUrl:(NSString *)url
{
    self.blockCycleUrl(url);
}


@end
